using Dapper;
using Eno.Domain.Repositories;
using Npgsql;

namespace Eno.Infrastructure.InfRepositories;

public class AppointOrRemoveRoleRepository : IAppointOrReomoveRoleRepository
{
    public readonly string _connectionString;

    public AppointOrRemoveRoleRepository(string connectionString)
    {
        _connectionString = connectionString;
    }

    public async Task<int> AppointRole(Guid rId, Guid uId)
    {
        using var conn = new NpgsqlConnection(_connectionString);
        var sql = @"insert into app_users_roles values(@RoleID,@UserID)";
        var number = await conn.ExecuteAsync(sql, new { RoleID = rId, UserID = uId });
        return number;

    }

    public async Task<int> RemoveRole(Guid rId, Guid uId)
    {
        await using var conn = new NpgsqlConnection(_connectionString);
        var sql = @"delete from app_users_roles where ""UsersID"" = @UID and ""RolesID""=@RID ";
        var number = await conn.ExecuteAsync(sql, new { UID = uId, RID = rId });
        return number;
    }


}